<?php

namespace App\Command;

use App\Base\ViewsInList;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class LazyEnCreateCommand extends Command
{

    protected static $defaultName = 'lazy:en:create';

    protected function configure()
    {
        $this
            ->setDescription('生产成单个数据库实体')
            ->addArgument('en', InputArgument::OPTIONAL, 'Entity Name')
            ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $entity = $input->getArgument('en');

        if ($entity) {
            $io->note(sprintf('您输入的实体名: %s', $entity));
            //从数据库导入
            //原始命令:php bin/console doctrine:mapping:import --path=src\Entity --filter=Car App\Entity annotation
            $command = $this->getApplication()->find('doctrine:mapping:import');
            $arguments = array(
                'command'       => 'doctrine:mapping:import',
                'mapping-type'  => 'annotation',
                'name'          => 'App\Entity',
                '--path'        => 'src\Entity',
                '--filter'      => $entity,
            );
            $greetInput = new ArrayInput($arguments);
            $command->run($greetInput, $output);
        }else{
            $io->error("请输入实体名称");
        }
    }

}
